<template>
	<view class="box" @click="goKefu">
		<image src="https://jw.xzsw2021.com/static/index/icon_53@2x.png" mode=""></image>
	</view>
</template>

<script>
	import Cache from '@/util/cache.js'
	import {
		getMarketServiceApi
	} from '@/api/market.js'
	export default {
		name: "kefu",
		data() {
			return {

			};
		},
		methods: {
			goKefu() {
				let market =Cache.get('market',true)
				if (market) {
					let key = `market:service:${market.id}`
					let serviceData = false
					if (Cache.get(key))
						serviceData = JSON.parse(Cache.get(key))
					if (!serviceData) {
						getMarketServiceApi(market.id).then(res => {
							if(!res.data){
								this.$showToast('当前菜市场无客服')
							}
							serviceData = res.data
							Cache.set(key, serviceData, 3600)
							uni.makePhoneCall({
								phoneNumber: serviceData.phone
							});
						}).catch(err => {

						})
					} else {
						if (!serviceData || !serviceData.phone) {
							this.$showToast('当前菜市场无客服')
						}
						uni.makePhoneCall({
							phoneNumber: serviceData.phone
						});
					}

				} else {
					this.$showToast('请先选择菜市场')
				}

			}
		}
	}
</script>

<style>
	.box {
		position: fixed;
		right: 20rpx;
		bottom: 62rpx;
		width: 133rpx;
		height: 133rpx;
		z-index: 21;
	}

	image {
		width: 133rpx;
		height: 133rpx;
	}
</style>
